<script lang="javascript">
    $("#car").live('click', function() {
        targetSearchHandler('car');
    });
    
    $("#product").live('click', function() {
        targetSearchHandler('product');
    });

    $("#service").live('click', function() {
        targetSearchHandler('service');
    });
    
    function targetSearchHandler(searchOption) {
        switch (searchOption) {
            case 'car':
                $("#search_car").show("slow");
                $("#search_product").hide("slow");
                $("#search_service").hide("slow");
                break;
            case 'product':
                $("#search_car").hide("slow");
                $("#search_product").show("slow");
                $("#search_service").hide("slow");
                break;
            case 'service':
                $("#search_car").hide("slow");
                $("#search_product").hide("slow");
                $("#search_service").show("slow");
                break;
        }
    }
    
    $(document).ready(function() {
        $("#search").submit(function(e) {                
            var invalid_number = false;                
            var element_val = $("#maxprice").val();
            if(element_val != '') {            
                var reg_number = /^[0-9]*$/;
                if(!reg_number.test(element_val))
                    invalid_number = true;

                var next_element = $("#maxprice").parent();
                $(next_element).find('div.error').remove();
            }

            if(invalid_number) {
                $("#maxprice").css('border-color', 'red');
                $(next_element).append('<div class="error">Invalid number</div>');                        
            }
            else 
                $(this).css('border', '1px solid #DADADA');

            if(invalid_number)
                e.preventDefault();
        }); 
    });    
</script>
<div id="content">
    <div class="container_medium">
	<h1 class="blue">What Do You Want to Search For?</h1>
        <ul>
            <li>
                <a id="car" href="#">Cars</a>
            </li>
            <li>
                <a id="product" href="#">Products</a>
            </li>
            <li>
                <a id="service" href="#">Services</a>
            </li>
        </ul>
        <div style="min-height: 20px; clear: both;"></div>        
        <div id="search_car" style="display: none;">
<?php 
        echo form_open(base_url()."index.php/car/advance", array('id' => 'search')); 
?>
            <table class="table_advance">
                <tr>
                    <td>Type</td>
                    <td>&nbsp;</td>
                    <td>Make</td>
                </tr>
                <tr>
                    <td>
                        <select name="cartype">
                            <option value="">Please select</option>
<?php 
                        foreach($type->result() as $row)
                        { 
        ?>
                            <option>
        <?php 
                                echo $row->name;
        ?>
                            </option>
        <?php
                        }
        ?>      
                        </select>                        
                    </td>
                    <td>&nbsp;</td>
                    <td>
                        <select name="make" id="make">
                            <option value="">Please select</option>
        <?php 
                            foreach($make->result() as $row)
                            { 
        ?>
                            <option value="<?php echo $row->id; ?>">
        <?php 
                                echo $row->name; 
        ?>
                            </option>
        <?php
                            }
        ?>        
                        </select>                        
                    </td>
                </tr>
                <tr>
                    <td>Maximum Price</td>
                    <td>&nbsp;</td>
                    <td>Model</td>
                </tr>
                <tr>
                    <td>
                        <input type="text" name="maxprice" class="number" id="maxprice" />
                    </td>
                    <td>&nbsp;</td>
                    <td>                
                        <select name="model" id="model">
                            <option value="">Please select</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>Location</td>
                    <td>&nbsp;</td>
                    <td>Dealer</td>
                </tr>
                <tr>
                    <td>
                        <select name="location">
                            <option value="">Please select</option>
        <?php 
                            foreach($location->result() as $row)
                            { 
        ?>
                            <option><?php echo $row->province ?></option>
        <?php
                            }
        ?>    
                        </select>                        
                    </td>
                    <td>&nbsp;</td>
                    <td>
                        <select name="dealer">
                            <option value="">Please select</option>
        <?php 
                            foreach($dealer->result() as $row)
                            { 
        ?>
                            <option><?php echo $row->company; ?></option>
        <?php
                            }
        ?>    
                        </select>
                    </td>
                </tr>
            </table>            
            <div style="min-height: 20px; clear: both;"></div>
            <h2 class="blue">Optional Search Filters</h2>
            <div style="min-height: 10px; clear: both;"></div>
            <table class="table_advance">
                <tr>
                    <td>Price range</td>
                    <td>&nbsp;</td>
                    <td>Mileage</td>
                </tr>
                <tr>
                    <td>
                        <select id="price_range" name="price_range">
                            <option value="0 - 0">Please select</option>
<?php
                        $start_price = 1000;
                        $deduction = 1000;
                        for($counter = 1; $counter <= 40; $counter++)
                        {
?>
                            <option>
<?php 
                                echo $start_price . ' - ' . ($start_price + 5000 - $deduction);
?>
                            </option>
<?php
                            $start_price += (5000 - $deduction);
                            $deduction = 0;                            
                        }
?>
                        </select>                        
                    </td>
                    <td>&nbsp;</td>
                    <td>
                        <select id="mileage_range" name="mileage_range">
                            <option value="0 - 0">Please select</option>
<?php
                        $start_mileage = 1000;
                        $deduction = 1000;
                        for($counter = 1; $counter <= 4; $counter++)
                        {
?>
                            <option>
<?php 
                                echo $start_mileage . ' - ' . ($start_mileage + 5000 - $deduction);
?>
                            </option>
<?php
                            $start_mileage += (5000 - $deduction);
                            $deduction = 0;                            
                        }
?>
                        </select>                         
                    </td>
                </tr>
                <tr>
                    <td>Year range</td>
                    <td>&nbsp;</td>
                    <td>Exterior color</td>
                </tr>
                <tr>
                    <td>
                        <select name="year_range">
                            <option value="0 - 0">Please select</option>
<?php                    
                        $start_year = date("Y");
                        for($counter = 0; $counter < 4; $counter++)
                        {
                            $start_year -= ($counter * 10);
?>
                            <option>
<?php
                                echo $start_year . ' - ' . ($start_year - 10);
?>
                            </option>
<?php
                        }
?>                        
                        </select>
                    </td>
                    <td>&nbsp;</td>
                    <td>
                        <select id="external_color" name="external_color" style="max-width: 252px;">
                            <option value="">Please select</option>
<?php 
                        foreach($color->result() as $row)
                        { 
?>
                            <option>
<?php 
                                echo $row->color; 
?>
                            </option>
<?php
                        }
?>    
                        </select>                        
                    </td>
                </tr>
                <tr>
                    <td>Drivetrain</td>
                    <td>&nbsp;</td>
                    <td>Transmission</td>
                </tr>
                <tr>
                    <td>
                        <select id="drivetrain" name="drivetrain">
                            <option value="">Please select</option>
<?php 
                        foreach($drivetrain->result() as $row)
                        { 
?>
                            <option>
<?php 
                                echo $row->drivetrain; 
?>
                            </option>
<?php
                        }
?>                                
                        </select>                        
                    </td>
                    <td>&nbsp;</td>
                    <td>
                        <select id="transmission" name="transmission">
                            <option value="">Please select</option>
<?php 
                        foreach($transmission->result() as $row)
                        { 
?>
                            <option>
<?php 
                                echo $row->transmission; 
?>
                            </option>
<?php
                        }
?>                                
                        </select>                        
                    </td>
                </tr>
                <tr>
                    <td colspan="3">Fuel</td>
                </tr>
                <tr>
                    <td colspan="3">
                        <ul style="display: inline;">
                            <li style="width: 100px;">
                                <input type="checkbox" value="0" name="fuel[]" />Gasoline
                            </li>                        
                            <li style="width: 100px;">
                                <input type="checkbox" value="1" name="fuel[]" />Diesel
                            </li>
                        </ul>
                    </td>
                </tr>
            </table> 
        <input type="submit" class="search" value="Search" />            
<?php 
        echo form_close();
?>                        
        </div>        
        <div id="search_product" style="display: none;">
            <h1 class="blue">Parts & Accessories</h1>
<?php 
        echo form_open(base_url()."index.php/part/result"); 
?>
            <table class="table_advance">
                <tbody>
                    <tr>
                        <td>Search for</td>
                        <td>&nbsp;</td>
                        <td>Make</td>
                    </tr>
                    <tr>
                        <td>
                            <select name="part">
                                <option value="">Please select</option>
        <?php 
                            foreach($part->result() as $row)
                            { 
        ?>
                                <option>
        <?php 
                                    echo $row->name;
        ?>
                                </option>
        <?php
                            }
        ?>      
                            </select>                   
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            <select name="make" id="make_part" class="row_non_insurance">
                                <option value="">Please select</option>
        <?php 
                            foreach($make->result() as $row)
                            { 
        ?>
                                <option value="<?php echo $row->id; ?>">
        <?php 
                                    echo $row->name;
        ?>
                                </option>
        <?php
                            }
        ?>                              
                            </select>                             
                        </td>
                    </tr>
                    <tr>
                        <td>Location</td>
                        <td>&nbsp;</td>
                        <td>Model</td>
                    </tr>
                    <tr>
                        <td>
                            <select name="location">
                                <option value="">Please select</option>
        <?php 
                            foreach($location->result() as $row)
                            { 
        ?>
                                <option>
        <?php 
                                    echo $row->province;
        ?>
                                </option>
        <?php
                            }
        ?>      
                            </select> 
                        </td>
                        <td>&nbsp;</td>
                        <td> 
                            <select name="model" id="model_part">
                                <option value="">Please select</option>
                            </select>                   
                        </td>
                    </tr>
                    <tr>
                        <td>Name</td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>
                            <select name="vendor">
                                <option value="">Please select</option>
        <?php 
                            foreach($dealer->result() as $row)
                            { 
        ?>
                                <option>
        <?php 
                                    echo $row->company;
        ?>
                                </option>
        <?php
                            }
        ?>      
                            </select>                   
                        </td>
                        <td></td>
                        <td>
                    
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <input type="submit" value="Search" name="submit" class="search" />
                        </td>
                    </tr>
                </tbody>
            </table>
<?php 
        echo form_close();
?>                        
        </div>
        <div style="min-height: 10px; clear: both;"></div>
        <div id="search_service" style="display: none;">
            <h1 class="blue">Service</h1>
<?php 
        echo form_open(base_url()."index.php/service/result"); 
?>
            <table class="table_advance">
                <tbody>
                    <tr>
                <td>Type of Service</td>
                <td>&nbsp;</td>                
                <td id="label_dynamic">Make</td>                
            </tr>
            <tr>
                <td>
                    <select name="service" id="service">
                        <option value="">Please select</option>
<?php 
                    foreach($service->result() as $row)
                    { 
?>
                        <option>
<?php 
                            echo $row->name;
?>
                        </option>
<?php
                    }
?>      
                    </select>                   
                </td>
                <td>&nbsp;</td>
                <td>
                    <input type="text" name="insurance" id="insurance" value="" class="hidden" />
                    <select name="make" class="row_non_insurance" id="make_service">
                        <option value="">Please select</option>
<?php 
                    foreach($make->result() as $row)
                    { 
?>
                        <option value="<?php echo $row->id; ?>">
<?php 
                            echo $row->name;
?>
                        </option>
<?php
                    }
?>                              
                    </select>                    
                </td>
            </tr>
            <tr class="row_non_insurance">
                <td>Location</td>
                <td>&nbsp;</td>
                <td>Model</td>
            </tr>
            <tr class="row_non_insurance">
                <td>
                    <select name="location">
                        <option value="">Please select</option>
<?php 
                    foreach($location->result() as $row)
                    { 
?>
                        <option>
<?php 
                            echo $row->province;
?>
                        </option>
<?php
                    }
?>      
                    </select> 
                </td>
                <td>&nbsp;</td>
                <td>
                    <select name="model" id="model_service">
                        <option value="">Please select</option>
                    </select>                       
                </td>
            </tr>
            <tr class="row_non_insurance">
                <td>Year</td>
                <td></td>
                <td></td>
            </tr>
            <tr class="row_non_insurance">
                <td>
                    <select name="year">
                        <option value="">Please select</option>
<?php
                    $current_year = date("Y");
                    for($counter = $current_year + 1; $counter >= 1950; $counter--)
                    {
?>
                        <option ><?php echo $counter; ?></option>
<?php                
                    }
?>                    
                    </select>
                </td>
                <td></td>
                <td></td>
            </tr>
                    <tr>
                        <td colspan="3">
                            <input type="submit" value="Search" name="submit" class="search" />
                        </td>
                    </tr>
                </tbody>
            </table>
<?php 
        echo form_close();
?>                        
        </div>
        <div style="min-height: 10px; clear: both;"></div>
    </div>    
    <div class="quicklink">
<?php 
        $this->load->view('/templates/quicklinks');
?>            
    </div>        
</div>
<div class="separator"></div>